﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RuleCode.Table;

namespace map.member.money
{
    public partial class WithDrawRecord : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
                BindWithDrawWebPager();
            }
        }

        #region 辅助方法
        /// <summary>
        /// 返回提现状态的字符串
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        protected string GetWithDrawStatusStr(int status)
        {
            string result = string.Empty;
            if (status == RuleCode.Enum.cbWithDrawStatus.Applicated)
                result = "已申请";
            else if (status == RuleCode.Enum.cbWithDrawStatus.Approved)
                result = "已审核";
            else if (status == RuleCode.Enum.cbWithDrawStatus.Failed)
                result = "提现失败";
            else if (status == RuleCode.Enum.cbWithDrawStatus.Finished)
                result = "提现成功";

            return result;
        }
        protected string GetAccountNumber(string accountNumber)
        {
            string result = string.Empty;
            if (accountNumber != string.Empty)
            {
                result = accountNumber;
                if (result.Length > 7)
                {
                    string newResult = result;
                    result = string.Empty;
                    for (int i = 0; i < newResult.Length; i++)
                    {
                        if (i % 4 == 0 && i != 0)
                            result += " ";
                        if (i < 4 || i > newResult.Length - 4)
                            result += newResult[i].ToString();
                        else
                            result += "*";
                    }
                }
            }
            return result;
        }

        private void InitPage()
        {
            DateTime now = DateTime.Now;
            this.StartDateTextBox.Text = now.Year.ToString() + "-" + now.Month.ToString() + "-1";
            this.EndDateTextBox.Text = now.ToShortDateString();
            this.WithDrawStatusDropDownList.Items.Clear();
            this.WithDrawStatusDropDownList.Items.Add(new ListItem("全部", ""));
            this.WithDrawStatusDropDownList.Items.Add(new ListItem("已申请", RuleCode.Enum.cbWithDrawStatus.Applicated.ToString()));
            this.WithDrawStatusDropDownList.Items.Add(new ListItem("已审核", RuleCode.Enum.cbWithDrawStatus.Approved.ToString()));
            this.WithDrawStatusDropDownList.Items.Add(new ListItem("提现失败", RuleCode.Enum.cbWithDrawStatus.Failed.ToString()));
            this.WithDrawStatusDropDownList.Items.Add(new ListItem("提现成功", RuleCode.Enum.cbWithDrawStatus.Finished.ToString()));
            this.WithDrawStatusDropDownList.SelectedIndex = 0;

        }
        #endregion

        #region 数据绑定
        private void BindWithDrawWebPager()
        {
            string filter = string.Empty;
            if (StartDateTextBox.Text != string.Empty)
                filter += " and WithDrawDate>= '" + StartDateTextBox.Text + "'";
            if (EndDateTextBox.Text != string.Empty)
                filter += " and WithDrawDate <= '" + EndDateTextBox.Text + " 23:59:59'";
            if (this.WithDrawStatusDropDownList.SelectedValue != "")
                filter += " and WithDrawStatus='" + this.WithDrawStatusDropDownList.SelectedValue + "'";

            cbWithDraw withDraw = cbWithDraw.Find("cbuserid='" + AliApi.appUserId + "' " + filter);
            this.WithDrawWebPager.DataSource = withDraw.MyTable;
            this.WithDrawWebPager.DataBind();

        }

        protected void WithDrawWebPager_PageIndexChanged(object sender, RuleCode.Controls.PageChangedEventArgs e)
        {
            WithDrawWebPager.CurrentPageIndex = e.NewPageIndex;
            BindWithDrawWebPager();
        }

        protected void SearchButton_Click(object sender, EventArgs e)
        {
            BindWithDrawWebPager();
        }
        #endregion
    }
}
